window.onload = function (){
    addMouseEvent();
}
const navMenuItems = document.querySelectorAll('#nav-menu a');

// 设置指示器的点击切换
function handleMenuItemClick(target){
    navMenuItems.forEach(item=>{
        item.classList.remove('active');
        item.style='';
    });
    target.classList.add('active');

    //设置要展示的内容
    const cueerntSection = document.querySelector('.active-section');
    cueerntSection.classList.remove('active-section');
    const newCurrentSection = document.querySelector(`.${target.getAttribute('data-rel')}`);
    newCurrentSection.classList.add('active-section');
}

navMenuItems.forEach(item=>{
    item.addEventListener('click',e=>handleMenuItemClick(e.target));
    item.classList.contains('active') && handleMenuItemClick(item);
});

function addMouseEvent(){
    if (isPhone()){
        let nameDom = document.getElementById('homeName');
        let mottoDom = document.getElementById('motto');
        nameDom.onclick = function (){
            if ('hidden' == document.getElementById('headImg').style.visibility){
                document.getElementById('headImg').style.visibility = '';
                document.getElementById('headText').style.visibility = 'hidden';
            }else{
                document.getElementById('headImg').style.visibility = 'hidden';
                document.getElementById('headText').style.visibility = '';
            }

        }
        mottoDom.onclick = function (){
            mottoDom.innerHTML = (mottoDom.innerHTML=='一个苦逼的程序猿◐▂◐'?
                '一个苦逼的程序猿◑▂◑':'一个苦逼的程序猿◐▂◐');
        }
    }else{
         let nameDom = document.getElementById('homeName');
         let mottoDom = document.getElementById('motto');
         nameDom.onmouseover = function (){
             document.getElementById('headImg').style.visibility = 'hidden';
             document.getElementById('headText').style.visibility = '';
         }
         nameDom.onmouseleave = function (){
             document.getElementById('headImg').style.visibility = '';
             document.getElementById('headText').style.visibility = 'hidden';
         }
         mottoDom.onmouseover = function (){
             mottoDom.innerHTML = '一个苦逼的程序猿◑▂◑';
         }
         mottoDom.onmouseleave = function(){
             mottoDom.innerHTML = '一个苦逼的程序猿◐▂◐';
         }
    }
}

function isPhone() {
    if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {
        return true;
    }
    else {
        return false;
    }
}

function showQQ(){
    document.getElementById('qqImg').style.visibility = '';
    document.getElementById('qqImg2').style.visibility = '';
}

function closeQQ(){
    document.getElementById('qqImg').style.visibility = 'hidden';
    document.getElementById('qqImg2').style.visibility = 'hidden';
}
